var adminPage;

$.blockUI.defaults.css.border = 'none';
$.blockUI.defaults.css.padding = '15px';
$.blockUI.defaults.css.backgroundColor = '#000';
$.blockUI.defaults.css.opacity = '0.6';
$.blockUI.defaults.css.color = '#fff';
//$.blockUI.defaults.css.message = '<h1><img src="./busy.gif" /> Loading...</h1>';
$.blockUI.defaults.css.timeout = '1000';

/*function createLayoutForAdmin()
{
	
	adminPage = $("#outerContentDiv").layout({
			scrollToBookmarkOnLoad:		false // handled by custom code so can 'unhide' section first
			,defaults: {
				
			}
	     	,west__paneSelector:		"#adminMainMenu"
	 		,center__paneSelector:	"#contentDiv"
	 		,spacing_open: 			5 
		 	,spacing_closed: 		5
		 	//,resizable: 			true
		 	,west__size:			300
		 	,north: {
		 		 paneSelector:			"#contentDiv"
		 		,size:					"auto"
		 		,spacing_open:			0
		 		,closable:				false
		 		,resizable:				false
			}

		 	,west: {
		 		paneSelector: 			"#adminMainMenu"
		 		,size: 					400
		 		,spacing_closed:		22
		 		,togglerLength_closed:	140
		 		,togglerAlign_closed: 	"west"
		 		,togglerContent_closed: "C<BR>o<BR>n<BR>t<BR>e<BR>n<BR>t<BR>s"
		 		,togglerTip_closed:		"Open & Pin Contents"
		 		,sliderTip: 			"Slide to Open Contents"
		 		,slideTrigger_open:		"mouseover"

		 	}
	 	});
	//adminPage.allowOverflow("north");
	scrollToBookmark( self.location.hash );
}*/

function getAddCompanyWin()
{
	$.blockUI();
	
	$.post('addCompanyPage.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}
function getAddDocTypeWin()
{
	$.blockUI();
	
	$.post('docTypePage.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function getAddBusinessUnitTypeWin()
{
	$.blockUI();
	
	$.post('addBussinessUnitTypePage.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}
function getAddDocSubCategoryWin()
{
	$.blockUI();
	
	$.post('addDocSubCategoryPage.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function getAddDocCategoryWin()
{
	$.blockUI();
	
	$.post('addDocCategoryPage.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function getAddLocationWin()
{
	$.blockUI();
	
	$.post('addLocationPage.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function getAddDepartmentWin()
{
	$.blockUI();
	
	$.post('addDepartmentPage.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function getAddUserWin()
{
	$.blockUI();
	
	$.post('addUserPage.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function addEntityForUserRoleMapping(formId){
	
	var userValue = $("#userIdResult").val();
	if(userValue == "")
		alert("The User ID cannot be blank.");	
	else{
		$.blockUI();
		
		var dataToSubmit = $("#"+formId).formSerialize();
		var url = $("#"+formId).attr('action');
		
		$.post(url,dataToSubmit,function(data){
				$(subContentDiv).empty().html(data);
				$.unblockUI();
		},"html");
	}
}

function addEntity(formId)
{
	$.blockUI();
	
	var dataToSubmit = $("#"+formId).formSerialize();
	var url = $("#"+formId).attr('action');
	
	$.post(url,dataToSubmit,function(data){
			$(subContentDiv).empty().html(data);
			$.unblockUI();
	},"html");
}

function searchUserForRole(formId)
{
	$.blockUI();
	
	var dataToSubmit = $("#"+formId).formSerialize();
	var url = $("#"+formId).attr('action');
	
		$.post(url,dataToSubmit,function(data){
			$(subContentDiv).empty().html(data);
			$.unblockUI();	
		},"html");
}

function getUser()
{
	$.blockUI();
	
	$.post('mapRoleToUser.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function loadAdminPage()
{
	$.blockUI();
	
	$.post('adminLogin.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function ViewCompany()
{
	$.blockUI();
	
	$.post('viewCompany.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function viewBusinessUnitType()
{
	$.blockUI();
	
	$.post('viewBusinessUnitType.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
	
}

function viewLocation()
{
	$.blockUI();
	
	$.post('viewLocation.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
	
}

function viewDepartment()
{
	$.blockUI();
	
	$.post('viewDepartment.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");		
	
}

function viewDocType()
{
	$.blockUI();
	
	$.post('viewDocType.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
	
}

function viewDocCategory()
{
	$.blockUI();
	
	$.post('viewDocCategory.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
	
}
function viewDocSubCategory()
{
	$.blockUI();
	
	$.post('viewDocSubCategory.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
	
}
function viewUser()
{
	$.blockUI();
	
	$.post('viewUser.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
	
}
function searchUserPage()
{
	$.blockUI();
	
	$.post('searchUserPage.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
	
}
function workFlowRole()
{
	$.blockUI();
	
	$.post('workFlowRoleAssigner.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
	
}	
function loadWFRoleMappingTable(){
	$.blockUI();
	
	var submitRoleData = $("#WFRoleAssigning").formSerialize();
	
	$.post('generateWFRoleAssignTable.htm',submitRoleData,function(data){
		$("#WFtable").empty().html(data);
		$.unblockUI();
	},"html");
	
}

function validate() {
		$.blockUI();
		
		var formData = $("#selectMasterDataForWF").formSerialize();
		
		if(formData != ""){
			$.post('submitMasterDataInMasterWFTable.htm',formData,function(data){
				$("#mainLayoutBody").empty().html(data);
				$.unblockUI();
			},"html");	
		}
		else{
			alert("Select Values");
		}
		
}

function addNewLocationDetails(){
	$.blockUI();
		
	$.post('addLocationMaster.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
	
	
}

function enableSelectButton(buttonId) {
	$("#"+buttonId).removeAttr("disabled");
	$("#"+buttonId).css({"opacity":"10","filter":"alpha(opacity=100)"});
}

function editCompany(){
	$.blockUI();
	
	$.post('editCompany.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function submitCompanyDetailsToEdit(){
	$.blockUI();
	$("#editCompanyDiv").css("display","block");
	
	var valueArray = $("#editCompany :checked").val().toString().split(",");

		$("#companyId").val(valueArray[0]);
		$("#companyName").val(valueArray[1]);
		$("#companyCode").val(valueArray[2]); 
		$("#companyAddress").val(valueArray[3]);
		$("#state").val(valueArray[6]);
		
		if(loadBelowValuesWhileEditingCompany('state','district')){
			$("#district").val(valueArray[5]);
		}
		if(loadBelowValuesWhileEditingCompany('district','city')){
			$("#city").val(valueArray[4]);
		}
		$("#child").val(valueArray[7]);
		$("#parentId").val(valueArray[8]);
		if(valueArray[9] == 'GroupHead'){
			$("#groupCompany").attr("checked","checked");
			enableDisableSelectCompany('groupCompany');
		}

		if(valueArray[9] == 'Subsidiary'){
			$("#subsidiaryCompany").attr("checked","checked");
			enableDisableSelectCompany('subsidiaryCompany');
			$("#parentId").val(valueArray[8]);
		}

		if(valueArray[9] == 'StandAlone'){
			$("#standAloneCompany").attr("checked","checked");
			enableDisableSelectCompany('standAloneCompany');
		}
	$.unblockUI();
}

function editBusinessUnitType(){
	$.blockUI();
	
	$.post('editBusinessUnitType.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function submitBusinessUnitTypeDetailsToEdit(){
	$.blockUI();
	
	var valueArray = $("#editBusinessUnitType :checked").val().toString().split(",");
	
	$("#typeCode").val(valueArray[0]);
	$("#typeName").val(valueArray[1]);
	
	$.unblockUI();
}


function editDepartment(){
	$.blockUI();
	
	$.post('editDepartmentDetails.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	});
}

function submitDepartmentDetailsToEdit(){
	$.blockUI();
	
	var valueArray = $("#editDepartmentDetails :checked").val().toString().split(",");
	
	$("#deparmentId").val(valueArray[0]);
	$("#departmentName").val(valueArray[1]);
	$("#departmentShortName").val(valueArray[2]);
	
	$.unblockUI();
}

function editLocation(){
	$.blockUI();
	
	$.post('editBusinessUnitDetails.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();	
	});
}

function submitBusinessUnitDetailsToEdit(){
	$.blockUI();
	
	var valueArray = $("#editBusinessUnitDetails :checked").val().toString().split(",");
	var ldId = valueArray[0];
	
	$.post('fetchDetailsOfSelectedBU.htm',{ldId:ldId},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	});
}

function editUser(){
	$.blockUI();
	
	$.post('searchUserToEdit.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function submitUserDetailsForEditing(){
	$.blockUI();
	
	var valueArray = $("#submitUserDetailsToEdit :checked").val().toString().split(",");
	
	$("#userName").val(valueArray[0]);
	$("#userDisplayName").val(valueArray[1]);
	$("#companySelect").val(valueArray[2]);
	$("#locationSelect").val(valueArray[3]);
	$("#department").val(valueArray[4]);
	$("#emailId").val(valueArray[5]);
	$("#strCreatedAuthor").val(valueArray[6]);
	$("#createdDate").val(valueArray[7]);
	$("#version").val(valueArray[8]);
	
	$.unblockUI();
}

function editDocType(){
	$.blockUI();
	
	$.post('editDocumentTypeDetails.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function submitTypeDetailsForEditing(){
	$.blockUI();
	
	var valueArray = $("#submitTypeDetailsToEdit :checked").val().toString().split(",");
	
	$("#dtId").val(valueArray[0]);
	$("#dtCode").val(valueArray[1]);
	$("#dtName").val(valueArray[2]);
	
	$.unblockUI();
}

function editDocCategory(){
	$.blockUI();
	
	$.post('editDocCategoryDetails.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	});
}

function submitCategoryDetailsForEditing(){
	$.blockUI();

	var valueArray = $("#submitCategoryToEdit input[type='radio']:checked").val().toString().split(",");
	
	$("#dcId").val(valueArray[0]);
	$("#dcName").val(valueArray[1]);
	$("#dcCode").val(valueArray[2]);
	$("#docType").val(valueArray[3]);
	
	$.unblockUI();
}

function editDocSubCategory(){
	$.blockUI();
	
	$.post('editDocSubCategoryDetails.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	});
}

function submitSubCategDetailsForEditing(){
	$.blockUI();
	
	var valueArray = $("#submitSubCategToEdit input[type='radio']:checked").val().toString().split(",");
	
	$("#dscId").val(valueArray[0]);
	$("#dscName").val(valueArray[1]);
	$("#docTypeID").val(valueArray[2]);
	//$("#docCatID").val(valueArray[3]);
	$("#dscCode").val(valueArray[4]);
	
	$.getJSON("fetchCategory.htm",{id: valueArray[2], ajax: 'true',parentlevel:valueArray[2]}, function(j){
		 var options = '';
		 if(j!=null)
		 {
		      for (var i = 0; i < j.length; i++) {
		        options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		      }
		      $("#docCatID").html(options);
		      $("#docCatID").val(valueArray[3]);
		      $.unblockUI();
		 }
	});
	
	
}

function filterUsersTable(filteraction){
	$.blockUI();
	var action = filteraction;
	var formData=$("#companySelect").val();
	
	$.post("fetchUsersAccToCompany.htm",{formData:formData, action:action},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	});
}

function filterCategList(){
	$.blockUI();
	
	var formData = $("#docTypeID").val();

	$.post("fetchCategAccToType.htm",{formData:formData},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	});
}

function filterSubCategList(){
	$.blockUI();
	
	var docCateg = $("#docCat").val();
	var docType = $("#docType").val();
	
	$.post("fetchSubCategAccToCateg.htm",{docType:docType , docCateg:docCateg},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	});
}


function deleteCompany(){
	$.blockUI();
	
	$.post('delCompany.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function submitCompanyDetailsTodel(){
	$.blockUI();
	
	var cdId = $("#delCompany :checked").val().toString();
		//alert(cdId);
	$.post('deleteCompany.htm',{cdId:cdId},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}



function loadCategory()
{
	$("#docType").change(function(){
	
		var docType = $("#docType").val();
		
		if($(this).val()!=0)
		{
			$.getJSON("fetchCategory.htm",{id: $(this).val(), ajax: 'true',parentlevel: docType}, function(j){
				 var options = '';
				 if(j!=null)
				 {
				      for (var i = 0; i < j.length; i++) {
				        options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
				      }
				      $("#docCat").html(options);
				      filterSubCategList();
				 }
			});
		}
	
	});
}

function loadCategoryForEditSubCateg()
{
	var docType = $("#docType").val();
	

	if(docType == 0){
		var options1 = '<option value="0"> ALL </option>';
		$("#docCat").html(options1);
		filterSubCategList();
	}
	else{
		filterAccToType(docType,0);
		/*var options2 = '';
		$.getJSON("fetchCategory.htm",{ajax: 'true',parentlevel: docType}, function(data){
			options2 += '<option value="0"> ALL </option>';
			
		
			
			if(data != null)
			 {
			      for (var i = 0; i < data.length; i++) {
			    	  //alert(data[i].optionValue + " : " + data[i].optionDisplay);
			    	options2 += '<option value="' + data[i].optionValue + '">' + data[i].optionDisplay + '</option>';
			      }
			      //alert(options2);
			      $("#docCat").html(options2);
			 }
		});*/
	}
}

function filterAccToType(docType,docCateg){
	$.blockUI();
	$.post("fetchSubCategAccToCateg.htm",{docType:docType , docCateg:docCateg},function(data,response){
		$(subContentDiv).empty().html(data);
		var options2 = '';
		/*$.getJSON("fetchCategory.htm",{ajax: 'true',parentlevel: docType}, function(data){
			options2 += '<option value="0"> ALL </option>';
			if(data != null)
			 {
			      for (var i = 0; i < data.length; i++) {
			    	  //alert(data[i].optionValue + " : " + data[i].optionDisplay);
			    	options2 += '<option value="' + data[i].optionValue + '">' + data[i].optionDisplay + '</option>';
			      }
			      //alert(options2);
			      $("#docCat").html(options2);
			 }
			$.unblockUI();
		});*/
		$.unblockUI();
		
	});
}

function loadBelowValuesWhileEditingCompany(selectId, selectIdToPopulate){
	var selectedId = $("#"+selectId).val();
//	alert("selectedId: " + selectedId + "selectIdToPopulate: " + selectIdToPopulate);
	var resultToreturn;
	
	if(selectId == 'state'){
		var options = '';
		if(selectedId != -1){
			$.getJSON(contextRoot + "loadRelatedBelowValuesForDistrict.htm",{selectedId:selectedId},function(jsonData){
				
				var numberOfData = jsonData.length;
				
				if(numberOfData > 0){
					 for (var i = 0; i < jsonData.length; i++) {
						 options += '<option value="' + jsonData[i].display + '">' + jsonData[i].display + '</option>';
					 }
					 options += '<option value="'+ -1 + '">' + "Others" + '</option>';
				 }else{
					 options += '<option value="'+ -1 + '">' + " " + '</option>';
					 
	//				 alert("No districts mapped to selected  state.");
				 }
				$("#"+selectIdToPopulate).empty().html(options);
				loadBelowValuesForCity(selectIdToPopulate);
				enableDisableStateFields('state');
			resultToreturn = true;
		});
		}
		else{
			options += '<option value="'+ -1 + '">' + "Others" + '</option>';
			$("#"+selectIdToPopulate).empty().html(options);
			$("#city").empty().html(options);
			enableDisableStateFields('state');
			resultToreturn = true;
		}
	}
	
	else if(selectId == 'district'){
		var options = '';
		if(selectedId != -1){
			$.getJSON(contextRoot + "loadRelatedBelowValuesForCity.htm",{selectedId:selectedId},function(jsonData){
				
				var numberOfData = jsonData.length;
				
				if(numberOfData > 0){
					 for (var i = 0; i < jsonData.length; i++) {
						 options += '<option value="' + jsonData[i].display + '">' + jsonData[i].display + '</option>';
					 }
					 options += '<option value="'+ -1 + '">' + "Others" + '</option>';
				 }else{
					 options += '<option value="'+ -1 + '">' + " " + '</option>';
	//				 alert("No city mapped to selected district.");
				 }
				
				$("#"+selectIdToPopulate).empty().html(options);
				enableDisableDistrictFields('district');
			resultToreturn = true;
			});
		}
		else{
			options += '<option value="'+ -1 + '">' + "Others" + '</option>';
			$("#"+selectIdToPopulate).empty().html(options);
			enableDisableDistrictFields('district');
			resultToreturn = true;
		}
	}

	return resultToreturn;
}

function loadBelowValues(selectId, selectIdToPopulate){
	var selectedId = $("#"+selectId).val();
//	alert("selectedId: " + selectedId + "selectIdToPopulate: " + selectIdToPopulate);

	if(selectId == 'state'){
		var options = '';
		if(selectedId != -1){
			$.getJSON(contextRoot + "loadRelatedBelowValuesForDistrict.htm",{selectedId:selectedId},function(jsonData){
				
				var numberOfData = jsonData.length;
				
				if(numberOfData > 0){
					 for (var i = 0; i < jsonData.length; i++) {
						 options += '<option value="' + jsonData[i].display + '">' + jsonData[i].display + '</option>';
					 }
					 options += '<option value="'+ -1 + '">' + "Others" + '</option>';
				 }else{
					 options += '<option value="'+ -1 + '">' + " " + '</option>';
					 
	//				 alert("No districts mapped to selected  state.");
				 }
				$("#"+selectIdToPopulate).empty().html(options);
				loadBelowValuesForCity(selectIdToPopulate);
				enableDisableStateFields('state');
			
		});
		}
		else{
			options += '<option value="'+ -1 + '">' + "Others" + '</option>';
			$("#"+selectIdToPopulate).empty().html(options);
			$("#city").empty().html(options);
			enableDisableStateFields('state');
		}
		
		
	}
	
	else if(selectId == 'district'){
		var options = '';
		if(selectedId != -1){
			$.getJSON(contextRoot + "loadRelatedBelowValuesForCity.htm",{selectedId:selectedId},function(jsonData){
				
				var numberOfData = jsonData.length;
				
				if(numberOfData > 0){
					 for (var i = 0; i < jsonData.length; i++) {
						 options += '<option value="' + jsonData[i].display + '">' + jsonData[i].display + '</option>';
					 }
					 options += '<option value="'+ -1 + '">' + "Others" + '</option>';
				 }else{
					 options += '<option value="'+ -1 + '">' + " " + '</option>';
	//				 alert("No city mapped to selected district.");
				 }
				
				$("#"+selectIdToPopulate).empty().html(options);
				enableDisableDistrictFields('district');
			});
		}
		else{
			options += '<option value="'+ -1 + '">' + "Others" + '</option>';
			$("#"+selectIdToPopulate).empty().html(options);
			enableDisableDistrictFields('district');
		}
		
	}
	
}

function loadBelowValuesForCity(selectId){
	var selectedId = $("#"+selectId).val();
//	alert("selectedId in loadBelowValuesForCity: " + selectedId);
	if(selectedId != -1){
		$.getJSON(contextRoot + "loadRelatedBelowValuesForCity.htm",{selectedId:selectedId},function(jsonData){
			var options = '';
			var numberOfData = jsonData.length;
			
			if(numberOfData > 0){
				 for (var i = 0; i < jsonData.length; i++) {
					 options += '<option value="' + jsonData[i].display + '">' + jsonData[i].display + '</option>';
				 }
				 options += '<option value="'+ -1 + '">' + "Others" + '</option>';
			 }else{
				 options += '<option value="'+ -1 + '">' + " " + '</option>';
	//			 alert("No city mapped to selected district.");
			 }
			
			$("#city").empty().html(options);
			enableDisableCityFields('city');
		});
	}
	
}


function loadLocForComp(selectId,selectIdToPopulate){
	var compId = $("#"+selectId).val();
	//alert(compId);
	if(compId == 0){
		var option1 = '';
		var option2 = '';
		option1 += '<option value="' + 0 + '">' + "Choose Location" + '</option>';
	 	option2 += '<option value="' + 0 + '">' + "Choose Department" + '</option>';
	 	$("#"+selectIdToPopulate).empty().html(option1);
	 	$("#department").empty().html(option2);
	}
	else{
		$.getJSON(contextRoot + "getLocForCompany.htm",{compId:compId},function(jsonData){
			var options='';
			var numOfOptions = jsonData.length;
			var option1='';
			var option2='';
			//alert(numOfOptions);
			if(numOfOptions > 0){
				 for (var i = 0; i < jsonData.length; i++) {
					 options += '<option value="' + jsonData[i].optionValue + '">' + jsonData[i].optionDisplay + '</option>';
					 $("#"+selectIdToPopulate).empty().html(options);
				 }
			 }
			 else{
				 	option1 += '<option value="' + 0 + '">' + "Choose Location" + '</option>';
				 	option2 += '<option value="' + 0 + '">' + "Choose Department" + '</option>';
				 	$("#"+selectIdToPopulate).empty().html(option1);
				 	$("#department").empty().html(option2);
				 	
				 	alert("No Locations Mapped To Company.");
			 }
			
			 if(numOfOptions > 0){
				 loadDepttForBU("locationSelect", "department");
			 }
		});
	}
	
}

function loadDepttForBU(selectId,selectIdToPopulate){
	var buId = $("#"+selectId).val();
	$.getJSON(contextRoot + "getDepttForBU.htm",{buId:buId},function(jsonData){
		var options = '';
		var option2='';
		 var numOfOptions = jsonData.length;
		
		 if(numOfOptions > 0){
			 options += '<option value="' + 0 + '">' + "All" + '</option>';
			 for (var i = 0; i < jsonData.length; i++) {
				 options += '<option value="' + jsonData[i].optionValue + '">' + jsonData[i].optionDisplay + '</option>';
				 $("#"+selectIdToPopulate).empty().html(options);
			 }
		 }else{
			 option2 += '<option value="' + 0 + '">' + "Choose Department" + '</option>';
			 $("#department").empty().html(option2);
			 alert("No Departments mapped to selected business unit.");
			 
		 }
		 if(buId == 0){
			 $("#department").empty();
		 }
		
	});
}


function getSelectCompanyType(){
	$.blockUI();
	
	$.post('selectCompanyType.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function selectedRadio(){
	$.blockUI();
	
	var selectedValue = $("#getCompanyType :checked").val();
	alert(selectedValue);
	$.post('addCompanyPage.htm',{selectedValue:selectedValue},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}


function enableDisableSelectCompany(selectId){
	var value = $("#" + selectId).val();

	if(value == "Subsidiary"){
		$("select.disableInputField").each(function(index){
			$(this).removeAttr("disabled");
			//$(this).addClass('infoTextBox highLightText1');
		});
	}else{
		$("select.disableInputField").each(function(index){
			$(this).attr("disabled","disabled");
		});
	}
}

function enableDisableStateFields(selectId){
	var value = $("#" + selectId).val();

	if(value == -1){		
//		$("input.disableInputField").each(function(index){
			$("#newState").removeAttr("disabled");
			$("#newDistrict").removeAttr("disabled");
			$("#newCity").removeAttr("disabled");
			//$(this).addClass('infoTextBox highLightText1');
//		});
	}
	else{
//		$("input.disableInputField").each(function(index){
			$("#newState").attr("disabled","disabled");
			$("#newDistrict").attr("disabled","disabled");
			$("#newCity").attr("disabled","disabled");
//		});
	}
}

function enableDisableDistrictFields(selectId){
	var value = $("#" + selectId).val();

	if(value == -1){		
		
		$("#newDistrict").removeAttr("disabled");
		$("#newCity").removeAttr("disabled");
			//$(this).addClass('infoTextBox highLightText1');
		
	}
	else{
		
		$("#newDistrict").attr("disabled","disabled");
		$("#newCity").attr("disabled","disabled");

	}
}

function enableDisableCityFields(selectId){
	var value = $("#" + selectId).val();

	if(value == -1){		
		
		$("#newCity").removeAttr("disabled");
			//$(this).addClass('infoTextBox highLightText1');
	}
	else{
		
		$("#newCity").attr("disabled","disabled");
		
	}
}

function mapSuperficialRoles(){
	$.blockUI();
	
	$.post('mapSuperficialRoles.htm',{data:'data'},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");
}

function fetchUserForRoles(){
	$.blockUI();
	
	var formData = $("#selectedRole").val();

	$.post('fetchUserForRole.htm',{formData:formData},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");

}

function submitUserForBuMapping(){
	$.blockUI();
	
	var formData = $("#submitUserForDetails input[type='radio']:checked").val();

	$.post('fetchUserDetailsForUserId.htm',{formData:formData},function(data){
		$(subContentDiv).empty().html(data);
		$.unblockUI();
	},"html");

}

function loadLocForCompTaskList(selectId,selectIdToPopulate){
	var compId = $("#"+selectId).val();
	//alert(compId);
	if(compId == 0){
		var option1 = '';
		var option2 = '';
		option1 += '<option value="' + 0 + '">' + "All" + '</option>';
	 	$("#"+selectIdToPopulate).empty().html(option1);
	 	$("#department").empty().html(option2);
	}
	else{
		$.getJSON(contextRoot + "getLocForCompany.htm",{compId:compId},function(jsonData){
			var options='';
			var numOfOptions = jsonData.length;
			var option1='';
			var option2='';
			//alert(numOfOptions);
			if(numOfOptions > 0){
				 for (var i = 0; i < jsonData.length; i++) {
					 options += '<option value="' + jsonData[i].optionValue + '">' + jsonData[i].optionDisplay + '</option>';
					 $("#"+selectIdToPopulate).empty().html(options);
				 }
			 }
			 else{
				 	option1 += '<option value="' + 0 + '">' + "All" + '</option>';
				 	$("#"+selectIdToPopulate).empty().html(option1);
				 	$("#department").empty().html(option2);
				 	
//				 	alert("No Locations Mapped To Company.");
			 }
			
			/* if(numOfOptions > 0){
				 loadDepttForBU("locationSelect", "department");
			 }*/
		});
	}
	
}